package net.joey.file;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class SteamDemo {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			FileOutputStream fos = new FileOutputStream("SteamTest.cc");
//			byte[] bs = "中文".getBytes("gbk");
			byte[] bs = "中文".getBytes("utf-8");
			System.out.println(bs.length);
			for(byte b:bs){
				System.out.println(Integer.toHexString(b));
				fos.write(b);
			}
			fos.close();
			System.out.println("---------");
			FileInputStream fis = new FileInputStream("SteamTest.cc");
			int b = -1;
			while((b = fis.read()) != -1){
				System.out.println(Integer.toHexString(b));
			}
			fis.close();
//			FileReader fr = new FileReader("SteamTest.cc");
//			InputStreamReader fr = new InputStreamReader(new FileInputStream("SteamTest.cc"),"utf-8");
			InputStreamReader fr = new InputStreamReader(new FileInputStream("SteamTest.cc"),"utf-8");
			System.out.println(fr.getEncoding());
			int c = -1;
			while((c = fr.read()) != -1){
				System.out.println(Integer.toHexString(c));
				System.out.println((char)c);
			}
			fr.close();
//			fos.write(1);
//			fos.write(49);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
